//
//  LZRushCouponDetailRulesOfUseCell.m
//  LzzizDemo
//
//  Created by xbnzd on 16/11/7.
//  Copyright © 2016年 xbnzd. All rights reserved.
//

#import "LZGrabCouponDetailRulesOfUseCell.h"
#import "GiftListLabel.h"

@interface LZGrabCouponDetailRulesOfUseCell()


/**
 使用注意事项
 */
@property (weak, nonatomic) IBOutlet GiftListLabel *rulesLabel;
@property (weak, nonatomic) IBOutlet UILabel *rulesCellTitleLabel;
@property (weak, nonatomic) IBOutlet GiftListLabel *guizeLabel;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *rulesLabelBottomToGuiZeLabelConstraint;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *rulesLabelBottomToSuperViewConstraint;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *guiZeLabelTopToTitleLabelConstraint;
@end

@implementation LZGrabCouponDetailRulesOfUseCell

- (void)awakeFromNib {
    [super awakeFromNib];
    [self configureLabel];
    
    self.rulesLabel.preferredMaxLayoutWidth = SCREEN_WIDTH - 20;
    self.guizeLabel.preferredMaxLayoutWidth = SCREEN_WIDTH - 20;
    // Initialization code
}


- (void)loadTitle:(NSString *)title contentStr:(NSString *)content guizeContent:(NSString *)guizeStr
{
    self.rulesCellTitleLabel.text = title;
    if (content.length == 0) {//没有使用条件
        self.guiZeLabelTopToTitleLabelConstraint.priority = 999;
        self.rulesLabelBottomToGuiZeLabelConstraint.priority = 250;
    }else{
        self.guiZeLabelTopToTitleLabelConstraint.priority = 250;
        self.rulesLabelBottomToGuiZeLabelConstraint.priority = 999;
    }
    
    if (guizeStr.length == 0) {
        self.rulesLabelBottomToSuperViewConstraint.priority = 999;
        self.rulesLabelBottomToGuiZeLabelConstraint.priority = 250;
    }else{
        self.rulesLabelBottomToSuperViewConstraint.priority = 250;
        self.rulesLabelBottomToGuiZeLabelConstraint.priority = 999;
    }
    [self setLabelContentText:content Label:self.rulesLabel];
    [self setLabelContentText:guizeStr Label:self.guizeLabel];
}

- (void)setLabelContentText:(NSString *)text Label:(GiftListLabel *)glabel
{
    if (text.length <= 0) {
        return;
    }
    extern CGFloat textLineSpace;
    NSMutableAttributedString *attStr = [[NSMutableAttributedString alloc] initWithString:text];
    NSMutableParagraphStyle *style = [[NSMutableParagraphStyle alloc] init];
    
    [style setLineSpacing:textLineSpace];
    [style setLineBreakMode:NSLineBreakByWordWrapping];
    [style setAlignment:NSTextAlignmentLeft];
    
    [attStr addAttribute:NSParagraphStyleAttributeName value:style range:NSMakeRange(0, attStr.length)];
    glabel.attributedText = attStr;
}

#pragma mark -
#pragma mark action
- (void)configureLabel
{
    [self.rulesLabel setVerticalAlignment:VerticalAlignmentTop];
    [self.guizeLabel setVerticalAlignment:VerticalAlignmentTop];
    
}


- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
